<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<script src="../js/mui.min.js"></script>
		
		<link rel="stylesheet" href="css/message.css" type="text/css" />
		<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
		<script src="../js/app.js"></script>
		<script type="text/javascript">
			var src="http://192.168.1.107/public/uploads/shop/";
			var mid=1;//我的id
			var mname ="小明";//我的名字
			var mtimg//我的头像
			var uname//好友名字
			var uid//好友id
			var utimg//好友头像
	
			
</script>
</head>
<body>
	<!--<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title" onclick="show()">我的好友</h1>
	</header>-->
<!--<div class="content"style="text-align:center;" >-->
        <div class="friend-list" id="friend-list" >
        	</div>
 <!--href='"
			+obj['user_id']+"&uname="+obj['user_name']
			+"'-->
<!--</div>-->
</body>

<!--document.getElementsByName(name)-->
<script type="text/javascript">
//加载好友列表
friends();
   //本地数据库内加载好友列表
function friends(){
	var fri=localStorage.getItem("friend");
	if(fri.length>5){
		result =eval("(["+localStorage.getItem("friend")+"])");
// 		alert("正在努力给你"+result+"，更新数据");
//localStorage.setItem(ckey,str);        
	var mess="";
for(var i=0;i<result.length;i++)
{
		
	mess+="<ul  id='friend"+result[i]['user_id']+"' class='hang' onclick='hang(this)'><a><li class='friend-hang-lia'><img src='"
			+src+result[i]['timg']+"'></li> <li class='friend-hang-lib'>"+result[i]['user_name']+"</li></a></ul>";
			}
document.getElementById("friend-list").innerHTML=mess;
	}else{
		friend();
	}};
//	document.getElementById("friend-list").innerHTML="dsffdsfds"+val;
	function hang(obj){
		//数据库存储当前点击id值
localStorage.setItem("chatkey",obj.id);
mui.openWindow('message.html');
	}
			
			//页面加载   获取全部好友列表
		function friend(){
			$.post("http://192.168.1.107/index/home/tongxun/api/friend.php", { name:mname, mid:mid },
			function(data){

				//result是一个集合,所以需要先遍历读取更新一条信息
			var	val="";
			var	ckey = "friend";
			$.each(data,function(index,obj)
			{
//					var value="{'user_name':'"+obj['user_name']+"','user_id':'"+obj['user_id']+"','timg':'"+obj['timg']+"'}";
			val+="{'user_name':'"+obj['user_name']+"','user_id':'"+obj['user_id']+"','timg':'"+obj['timg']+"'},";
				
			$("#friend-list").append("<ul  id='friend"+obj['user_id']+"' class='hang' onclick='hang(this)'><a><li class='friend-hang-lia'><img src='"
			+src+obj['timg']+"'></li> <li class='friend-hang-lib'>"+obj['user_name']+"</li></a></ul>");
//val+="fdsfsdf";
			});
			val=val.trim(",","right");//每次连接完毕删除结尾逗号
			localStorage.setItem(ckey,val); 
//			alert(ckey+val); 
			},'json');//这个json 是请求返回数据类型，不写的话默认是字符串类型
			}
</script>
</html>